package main

import (
	"fmt"
	"gee"
	"net/http"
)

var VERSION = "v1.0.0"

func main() {
	g := gee.New()
	g.Use(gee.Logger())
	g.GET("/", indexHandler)
	g.GET("/hello", helloHandler)
	g.GET("/hi", HiHandler)
	g.GET("/health", healthHandler)
	g.Run(":8080")
}

// handler echoes r.URL.Path
func indexHandler(c *gee.Context) {
	fmt.Fprintf(c.Writer, "URL.Path = %q\n", c.Path)
}

// handler echoes r.URL.Header
func helloHandler(c *gee.Context) {
	for k, v := range c.Request.Header {
		fmt.Fprintf(c.Writer, "Header[%q] = %q\n", k, v)
	}
}

// handler echoes r.URL.Header
func HiHandler(c *gee.Context) {
	c.JSON(200, gee.H{"name": "ding"})
}

//1.request header->response header
//2.get VERSION config and write to response
//3.log client IP,HTTP code
//4.Visit /health and return 200
func healthHandler(c *gee.Context) {
	for key, value := range c.Request.Header {
		c.Writer.Header().Set(key, fmt.Sprint(value))
	}
	c.JSON(200, gee.H{"code": http.StatusOK, "VERSION": VERSION})
}
